package com.wmssystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wmssystem.dto.Result;
import com.wmssystem.entity.MaterialDetailMaintenance;
import com.wmssystem.entity.ReceiveMaterial;
import com.wmssystem.service.impl.MaterialDetailMaintenanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("materialDetailMaintenance")
@ResponseBody
public class MaterialDetailMaintenanceController {
    @Autowired
    MaterialDetailMaintenanceService materialDetailMaintenanceService;

    /**
     * 收料单维护-新增
     * @param maintenance
     * @return
     */
    @PostMapping("increase")
    public Result increase(@RequestBody MaterialDetailMaintenance maintenance) {
        maintenance.setStatus("未接收");
        materialDetailMaintenanceService.save(maintenance);
        return Result.ok("添加成功");
    }

    /**
     * 收料单维护-更新
     * @param maintenance
     * @return
     */
    @PostMapping("update")
    public Result update(@RequestBody MaterialDetailMaintenance maintenance) {
        materialDetailMaintenanceService.updateById(maintenance);
        return Result.ok("更新成功");
    }

    /**
     * 收料单维护-删除
     * @param MDMId
     * @return
     */
    @DeleteMapping("delete")
    public Result delete(Long MDMId) {
        log.info(MDMId.toString());
        materialDetailMaintenanceService.removeById(MDMId);
        return Result.ok("删除成功");
    }

    /**
     * 物料明细--查找
     * @param page
     * @param size
     * @return
     */
    @GetMapping("query")
    public Result query(@RequestParam(value = "page", defaultValue = "1") Integer page,
                        @RequestParam(value = "size", defaultValue = "10") Integer size) {
        Page<MaterialDetailMaintenance> Page = new Page<>(page,size);
        materialDetailMaintenanceService.page(Page, new QueryWrapper<MaterialDetailMaintenance>().orderByAsc("material_detail_maintenance_id"));
        List<MaterialDetailMaintenance> materialDetailMaintenances = Page.getRecords();
        return Result.ok(materialDetailMaintenances);
    }


}
